package com.jiuli_travel.attraction_service.model.dto.attraction;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.jiuli_travel.attraction_service.model.entity.Attraction;
import com.jiuli_travel.utils.PageQuery;
import lombok.Data;

import java.math.BigDecimal;
import java.time.LocalDateTime;

@Data
public class AttractionQueryRequest extends PageQuery<Attraction> {

    /**
     * 搜索文本
     */
    private String searchText;  //最重要的一个模块

    /**
     * 景点名称
     */
    private String name;

    /**
     * 经度
     */
    private Float longitude;

    /**
     * 纬度
     */
    private Float latitude;

    /**
     * 景点类别
     */
    private String tags;

    /**
     * 景点单独门票价格（如有 默认为成年人票价）
     */
    private BigDecimal admissionFee;

    /**
     * 景点简介
     */
    private String description;

    /**
     * 景点开放时间
     */
    private String openingHours;

    /**
     * 用户评分
     */
    private Integer min_rating;

    private Integer max_rating;


    //构造查询条件
    public LambdaQueryChainWrapper<Attraction> toQueryWrapper(){
        LambdaQueryChainWrapper<Attraction> queryWrapper =
                new LambdaQueryChainWrapper<Attraction>(Attraction.class);

        //具体查询景点类别
        queryWrapper
                .eq(tags != null ,Attraction::getTags, this.tags);


        //模糊查询景点名称和景点简介 （搜索文本）
        if(searchText != null) {
            queryWrapper
                    .like(Attraction::getName, searchText)
                    .or()
                    .like(Attraction::getDescription, searchText);
        }

        //用户评分
        queryWrapper
                .ge(min_rating != null, Attraction::getRating, min_rating)
                .le(max_rating != null, Attraction::getRating, max_rating);

        //position

        return queryWrapper;
    }
}
